<?php
namespace app\admin\controller;

use think\Config;

class Excel extends Base{
	
	
	 public function exportExcel($data = array(), $title = array(), $filename = 'report')
    {	
	
		 	$title  = array(
		'账号序列',
		 '名字',
		'手机号',
		'产品',
		'尺寸',
		'地址',
		'收货地址',
		'付款方式',
		'购买时间',
		'留言'
		 );
		 $data = array();
		 $order=['create_time'=>'desc'];
         $select = M('message')->order($order)->select();
		
		 foreach($select as $k=> $st){
			 //$co=json_decode($st['tags_value'], true);
			 // echo $co->tel;exit;
			  // print_r($co);exit;
			
			 $data[$k]['id']=$st['id'];
			 $data[$k]['name']=$st['name'];
			 $data[$k]['tel']=$st['tel'];
			 $data[$k]['chanpin']=$st['chanpin'];
			 $data[$k]['size']=$st['size'];
			 $data[$k]['address']=$st['bdprovince'].$st['bdcity'].$st['bdarea'];
			 $data[$k]['dizhi']=$st['dizhi'];
			 $data[$k]['fukuan']="货到付款";
		     $data[$k]['create_time']=date('Y-m-d h:i:sa', $st['create_time']);
			 $data[$k]['liuyan']=$st['liuyan'];
		 }
		// print_r($data);exit;
		$filename="购买列表";
		
        header("Content-type:application/octet-stream");
        header("Accept-Ranges:bytes");
        header("Content-type:application/vnd.ms-excel");
        header("Content-Disposition:attachment;filename=" . $filename . ".xls");
        header("Pragma: no-cache");
        header("Expires: 0");

        //导出xls 开始
        if (!empty($title)) {
            foreach ($title as $k => $v) {
                $title[$k] = iconv("UTF-8", "GB2312", $v);
            }
            $title = implode("\t", $title);
           echo "$title\n";
       }

       if (!empty($data)) {
           foreach ($data as $key => $val) {
               foreach ($val as $ck => $cv) {
                   $data[$key][$ck] = iconv("UTF-8", "GB2312", $cv);
               }
               $data[$key] = implode("\t", $data[$key]);

           }
           echo implode("\n", $data);
       }
		
    }
	
  	

   
}
